﻿
// ClientDoc.cpp: CClientDoc 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "Client.h"
#endif

#include "ClientDoc.h"

#include <propkey.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CClientDoc

IMPLEMENT_DYNCREATE(CClientDoc, CDocument)

BEGIN_MESSAGE_MAP(CClientDoc, CDocument)
END_MESSAGE_MAP()


// CClientDoc 构造/析构

CClientDoc::CClientDoc() noexcept
{
	// TODO: 在此添加一次性构造代码

}

CClientDoc::~CClientDoc()
{
}

BOOL CClientDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: 在此添加重新初始化代码
	// (SDI 文档将重用该文档)

	return TRUE;
}




// CClientDoc 序列化

void CClientDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: 在此添加存储代码
	}
	else
	{
		// TODO: 在此添加加载代码
	}
}

#ifdef SHARED_HANDLERS

// 缩略图的支持
void CClientDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
	// 修改此代码以绘制文档数据
	dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));

	CString strText = _T("TODO: implement thumbnail drawing here");
	LOGFONT lf;

	CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
	pDefaultGUIFont->GetLogFont(&lf);
	lf.lfHeight = 36;

	CFont fontDraw;
	fontDraw.CreateFontIndirect(&lf);

	CFont* pOldFont = dc.SelectObject(&fontDraw);
	dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
	dc.SelectObject(pOldFont);
}

// 搜索处理程序的支持
void CClientDoc::InitializeSearchContent()
{
	CString strSearchContent;
	// 从文档数据设置搜索内容。
	// 内容部分应由“;”分隔

	// 例如:     strSearchContent = _T("point;rectangle;circle;ole object;")；
	SetSearchContent(strSearchContent);
}

void CClientDoc::SetSearchContent(const CString& value)
{
	if (value.IsEmpty())
	{
		RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
	}
	else
	{
		CMFCFilterChunkValueImpl *pChunk = nullptr;
		ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
		if (pChunk != nullptr)
		{
			pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
			SetChunkValue(pChunk);
		}
	}
}

#endif // SHARED_HANDLERS

// CClientDoc 诊断

#ifdef _DEBUG
void CClientDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CClientDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

BEGIN_INTERFACE_MAP(CClientDoc, CDocument)
	INTERFACE_PART(CClientDoc, IID_IOleClientSite, COleClientSite)
	INTERFACE_PART(CClientDoc, IID_IAdviseSink, COleAdviseSink)
END_INTERFACE_MAP()

IOleClientSite* CClientDoc::GetClientSite()
{
    IOleClientSite* p = nullptr;
    m_xCOleClientSite.QueryInterface(IID_IOleClientSite, (void**)&p);
    return p;
}

IAdviseSink* CClientDoc::GetAdviseSink()
{
    IAdviseSink* p = nullptr;
    m_xCOleAdviseSink.QueryInterface(IID_IAdviseSink, (void**)&p);
    return p;
}

ULONG CClientDoc::XCOleClientSite::AddRef()
{
    METHOD_PROLOGUE(CClientDoc, COleClientSite);
    return pThis->ExternalAddRef();
}

ULONG CClientDoc::XCOleClientSite::Release()
{
    METHOD_PROLOGUE(CClientDoc, COleClientSite);
    return pThis->ExternalRelease();
}

HRESULT CClientDoc::XCOleClientSite::QueryInterface(REFIID iid, void** ppvObj)
{
    METHOD_PROLOGUE(CClientDoc, COleClientSite);
    return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}

HRESULT __stdcall CClientDoc::XCOleClientSite::SaveObject()
{
    return S_OK;
}

HRESULT __stdcall CClientDoc::XCOleClientSite::GetMoniker(IN DWORD dwAssign, IN DWORD dwWhichMoniker, OUT IMoniker** ppmk)
{
    return E_NOTIMPL;
}

HRESULT __stdcall CClientDoc::XCOleClientSite::GetContainer(OUT IOleContainer** ppContainer)
{
    return E_NOTIMPL;
}

HRESULT __stdcall CClientDoc::XCOleClientSite::ShowObject()
{
    return S_OK;
}

HRESULT __stdcall CClientDoc::XCOleClientSite::OnShowWindow(IN BOOL fShow)
{
    return S_OK;
}

HRESULT __stdcall CClientDoc::XCOleClientSite::RequestNewObjectLayout()
{
    return E_NOTIMPL;
}

ULONG CClientDoc::XCOleAdviseSink::AddRef()
{
    METHOD_PROLOGUE(CClientDoc, COleAdviseSink);
    return pThis->ExternalAddRef();
}

ULONG CClientDoc::XCOleAdviseSink::Release()
{
    METHOD_PROLOGUE(CClientDoc, COleAdviseSink);
    return pThis->ExternalRelease();
}

HRESULT CClientDoc::XCOleAdviseSink::QueryInterface(REFIID iid, void** ppvObj)
{
    METHOD_PROLOGUE(CClientDoc, COleAdviseSink);
    return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj);
}

void __stdcall CClientDoc::XCOleAdviseSink::OnDataChange(IN FORMATETC* pFormatetc, IN STGMEDIUM* pStgmed)
{
}

void __stdcall CClientDoc::XCOleAdviseSink::OnViewChange(IN DWORD dwAspect, IN LONG lindex)
{
    METHOD_PROLOGUE(CClientDoc, COleAdviseSink);
    pThis->UpdateAllViews(NULL);
}

void __stdcall CClientDoc::XCOleAdviseSink::OnRename(IN IMoniker* pmk)
{
}

void __stdcall CClientDoc::XCOleAdviseSink::OnSave()
{
}

void __stdcall CClientDoc::XCOleAdviseSink::OnClose()
{
}
